program ProceduresForLists;

{$APPTYPE CONSOLE}

uses
  SysUtils;
type
  pelement=^element;
  element=record
    value:integer;
    next:pelement;
  end;
var
  tmp: pelement;
  procedure AddToBegin (var head:pelement; num:integer);
  begin
    tmp:=head;
    new(head);
    head^.value:=num;
    head^.next:=tmp;
  end;
  procedure DisposeFromBegin (var head:pelement; num:integer);
  var  tmp : pelement;
  begin
    tmp := head^.next;
    dispose (head);
    head := tmp;
  end;
  procedure AddToEnd (var head:pelement; num:integer);
  var
    current: pelement;
  begin
    if (head<>nil) then
    begin
    current:=head;
    while(current^.next<>nil) do
      current:=current^.next;
    new(current^.next);
    current^.next^.value:=num;
    current^.next^.next:=nil;
    end else
    begin
    AddToBegin(head, num);
    end;
  end;
  procedure DisposeFromEnd (var head:pelement);
  var
    current: pelement;
  begin
   if (head<>nil) then
    begin
      current:=head;
      while(current^.next^.next<>nil) do
        current:=current^.next;
      dispose(current^.next^.next);
      current^.next:=nil;
    end;
  end;
  procedure PrintList (head:pelement);
  var
    current:pelement;
  begin
    current:=head;
    while (current<>nil) do
    begin
      writeln(current^.value);
      current:=current^.next;
    end;
  end;


begin

end.
